package com.lanxiao.cloud.modules.gateway.route.application.query;

import com.lanxiao.cloud.common.core.enums.DelFlagEnum;
import com.lanxiao.cloud.common.core.utils.StringUtils;
import com.lanxiao.cloud.common.mybatis.query.QueryWrapper;
import com.lanxiao.cloud.modules.gateway.route.domain.model.GatewayRoute;
import java.util.Date;
import java.util.Objects;

/**
 * @author ：qiaoliang
 * @date ：2021-09-14
 */
public class RouteLambdaQueryWrapper extends QueryWrapper<GatewayRoute> {


  public static RouteLambdaQueryWrapper wrapper() {
    return new RouteLambdaQueryWrapper();
  }


  public RouteLambdaQueryWrapper queryWrapper(RouteLambdaQuery query) {
    queryWrapper.eq(StringUtils.isNotBlank(query.getServiceId()),
            GatewayRoute::getServiceId, query.getServiceId())
        .eq(StringUtils.isNotBlank(query.getUri()),
            GatewayRoute::getUri, query.getUri())
        .eq(StringUtils.isNotBlank(query.getPredicates()),
            GatewayRoute::getPredicates, query.getPredicates())
        .eq(StringUtils.isNotBlank(query.getFilters()),
            GatewayRoute::getFilters, query.getFilters())
        .eq(Objects.nonNull(query.getCreatedBy()),
            GatewayRoute::getCreateBy, query.getCreatedBy());
    return this;
  }

  public RouteLambdaQueryWrapper eqDelFlag(DelFlagEnum delFlagEnum) {
    queryWrapper.eq(GatewayRoute::getDelFlag, delFlagEnum);
    return this;
  }

  public RouteLambdaQueryWrapper geTime(Date date) {
    queryWrapper.ge(Objects.nonNull(date), GatewayRoute::getCreateTime, date);
    return this;
  }

}
